import java.io.*;

public class CopyBytes {
    public static void main(String[] args) throws IOException {
        FileInputStream fileInputStream = new FileInputStream("D:\\Copy\\byteStream\\farrago.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\Copy\\byteStream\\outAgain.txt");
        try {

            int c;
            while((c = fileInputStream.read()) != -1){
                fileOutputStream.write(c);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            fileInputStream.close();
            fileOutputStream.close();
        }
        System.out.println("原文件内容：");
        printFileContent("D:\\Copy\\byteStream\\farrago.txt");
        System.out.println("复制后文件内容：");
        printFileContent("D:\\Copy\\byteStream\\outAgain.txt");
    }
    private static void printFileContent(String filename) {
        try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}